package com.dizner.dimagepicker;

import android.text.TextUtils;

import androidx.annotation.NonNull;

import java.io.File;
import java.util.Objects;

public class ImageDir implements Comparable<ImageDir> {
    private String path;
    private String dirName;
    private String extName;
    private int imagesCount;


    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getDirName() {
        return dirName;
    }

    public void setDirName(String dirName) {
        this.dirName = dirName;
    }

    public String getExtName() {
        return extName;
    }

    public void setExtName(String extName) {
        this.extName = extName;
    }

    public int getImagesCount() {
        return imagesCount;
    }

    public void setImagesCount(int imagesCount) {
        this.imagesCount = imagesCount;
    }

    public static ImageDir getAImageDirBean(@NonNull Image image) {

        return getAImageDirBean(image.getPath());
    }

    public static ImageDir getAImageDirBean(@NonNull String imagePath) {
        if (TextUtils.isEmpty(imagePath)) {
            return null;
        }

//        imagePath = imagePath.replace("//", "/");

        int index = imagePath.lastIndexOf(File.separator);

        String filePath = imagePath.substring(0, index);

        int index1 = filePath.lastIndexOf(File.separator);

        String fileDirName = filePath.substring(index1 + 1);

        ImageDir dir = new ImageDir();

        dir.setPath(filePath);


        String extName = Utils.getFileDirExtName(filePath);
        if (TextUtils.isEmpty(extName)) {
            dir.setDirName(fileDirName);
        }else {
            dir.setDirName(extName);
        }
//        dir.setExtName(extName);

        return dir;
    }

    @Override
    public int compareTo(ImageDir obj) {
        return getPath().compareTo(obj.getPath());
    }
}
